package com.yincheng.oes.business.repository;

import com.yincheng.oes.attachment.entity.Attachment;
import com.yincheng.oes.attachment.mapper.AttachmentMapper;
import com.yincheng.oes.business.model.dto.PageResultDTO;
import com.yincheng.oes.business.model.query.DownloadListReq;
import com.yincheng.oes.business.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

/**
 * @Description TODO
 * @Author 446948434@qq.com
 * @Date 2021/10/24 9:35 下午
 * @Version 1.0
 */
@Component
public class FileResourceManager {

    @Autowired
    private AttachmentMapper attachmentMapper;

    /**
     * 分页查询我的下载文件
     * @param req 分页查询参数
     * @return 我的下载文件
     */
    public PageResultDTO<Attachment> pagingQuery(DownloadListReq req){
        if (Objects.isNull(req)){
            return null;
        }
        if(Objects.isNull(req.getPage())){
            Page page = new Page();
            page.setPageSize(10);
            req.setPage(page);
        }
        PageResultDTO<Attachment> pageResult = new PageResultDTO<>();
        int total = attachmentMapper.countByParam(req);
        req.getPage().setTotal(total);
        pageResult.setPage(req.getPage());
        pageResult.setTotal(total);
        List<Attachment> attachments = attachmentMapper.selectByParam(req);
        pageResult.setResults(attachments);
        return pageResult;
    }


}
